From 565f279e0732f15734ee8cf25a393bbf42a80072 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Thu, 24 May 2007 14:02:09 +0100 Subject: [PATCH] xend: Fix CPU affinity reset across save/restore. Fixes bug #936. Signed-off-by: Masaki Kanno --- tools/python/xen/xend/XendConfig.py | 64 ++++++++++++++++++----------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/tools/python/xen/xend/XendConfig.py b/tools/python/xen/xend/XendConfig.py index 14e0444df8..397fc437e8 100644 --- a/tools/python/xen/xend/XendConfig.py +++ b/tools/python/xen/xend/XendConfig.py @@ -587,30 +587,46 @@ class XendConfig(dict): else: cfg['cpus'] = str(cfg['cpu']) - # convert 'cpus' string to list of ints - # 'cpus' supports a list of ranges (0-3), seperated by - # commas, and negation, (^1). - # Precedence is settled by order of the string: - # "0-3,^1" -> [0,2,3] - # "0-3,^1,1" -> [0,1,2,3] - try: - if 'cpus' in cfg and type(cfg['cpus']) != list: - cpus = [] - for c in cfg['cpus'].split(','): - if c.find('-') != -1: - (x, y) = c.split('-') - for i in range(int(x), int(y)+1): - cpus.append(int(i)) - else: - # remove this element from the list - if c[0] == '^': - cpus = [x for x in cpus if x != int(c[1:])] + # Convert 'cpus' to list of ints + if 'cpus' in cfg: + cpus = [] + if type(cfg['cpus']) == list: + # If sxp_cfg was created from config.sxp, + # the form of 'cpus' is list of string. + # Convert 'cpus' to list of ints. + # ['1'] -> [1] + # ['0','2','3'] -> [0,2,3] + try: + for c in cfg['cpus']: + cpus.append(int(c)) + + cfg['cpus'] = cpus + except ValueError, e: + raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e)) + else: + # Convert 'cpus' string to list of ints + # 'cpus' supports a list of ranges (0-3), + # seperated by commas, and negation, (^1). + # Precedence is settled by order of the + # string: + # "0-3,^1" -> [0,2,3] + # "0-3,^1,1" -> [0,1,2,3] + try: + for c in cfg['cpus'].split(','): + if c.find('-') != -1: + (x, y) = c.split('-') + for i in range(int(x), int(y)+1): + cpus.append(int(i)) else: - cpus.append(int(c)) - - cfg['cpus'] = cpus - except ValueError, e: - raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e)) + # remove this element from the list + if c[0] == '^': + cpus = [x for x in cpus if x != int(c[1:])] + else: + cpus.append(int(c)) + + cfg['cpus'] = cpus + except ValueError, e: + raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e)) if 'security' in cfg and isinstance(cfg['security'], str): cfg['security'] = sxp.from_string(cfg['security']) @@ -842,6 +858,8 @@ class XendConfig(dict): if name in self and self[name] not in (None, []): if typ == dict: s = self[name].items() + elif typ == list: + s = self[name] else: s = str(self[name]) sxpr.append([name, s]) -- 2.30.2